package com.hot100.easy;

import java.util.Stack;

/**
 * @ClassName Demo17
 * @Description 回文链表
 * @Author zt
 * @Date 16:40 2022/6/11
 * @Version 1.0
 **/
public class Demo17 {

    public static void main(String[] args) {

    }
    public boolean isPalindrome(ListNode head) {
        ListNode temp=head;
        if(head==null||head.next==null){
            return true;
        }
        Stack<Integer> stack=new Stack<>();
        while (head!=null){
           stack.push(head.val);
           head=head.next;
        }
        while (!stack.empty()){
            Integer pop = stack.pop();
            int val = temp.val;
            if(!pop.equals(val)){
                return false;
            }
            temp=temp.next;
        }
      return true;
    }


    public class ListNode {
        int val;
        ListNode next;
        ListNode() {}
        ListNode(int val) { this.val = val; }
        ListNode(int val, ListNode next) { this.val = val; this.next = next; }
    }

}